import {
	defineStore
} from 'pinia'
console.log(localStorage.getItem('userInfo'))
export const useUserStore = defineStore('user', {
	state: () => {
		return {
			userInfo: localStorage.getItem('userInfo')?JSON.parse(localStorage.getItem('userInfo')) : {},
			token:localStorage.getItem('token')?localStorage.getItem('token') : ''
		}
	},
	actions: {
		setUserInfo(data) {
			this.userInfo = data
			localStorage.setItem('userInfo', JSON.stringify(data))
			
		},
		setToken(data){
			this.token = data
			localStorage.setItem('token', data)
		},
		logout(){
			this.userInfo = {};
			this.token = ''
			localStorage.removeItem('userInfo');
			localStorage.removeItem('token')
		}
	}
})
